package com.Webserver.core;

import com.Webserver.http.HttpRequest;
import com.Webserver.http.HttpResponse;
import java.io.File;
/**
 * 用于处理请求.
 */
public class DispatcherServlet {
    public void server(HttpRequest request, HttpResponse response){
        String path = request.getUri();
        File file = new File("./webapps" + path);
        //如果请求的资源存在并且是一个文件则正确.
        if (file.exists() && file.isFile()) {
            response.setEntity(file);//调用响应对象,判断
        } else {
            response.setStatusCode(404);
            response.setStatusReason("NotFound");
            response.setEntity(new File("./webapps/root/404.html"));
        }
    }
}
